package com.briup.cms.service;

import com.briup.cms.bean.Comment;
import com.briup.cms.dao.CommentMapper;
import com.briup.cms.exception.CustomerException;
import com.briup.cms.utils.MessageStatus;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper mapper;

    @Override
    public PageInfo<Comment> pageQueryAll(int pageNum, int pageSize) throws CustomerException {
        PageHelper.startPage(pageNum,pageSize,true);
        List<Comment> list = mapper.findAll();
        PageInfo<Comment> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public void updateCommentByStatus(int id, int status) throws CustomerException {
        mapper.updateCommentByStatus(id,status);
    }

    @Override
    public void deleteById(int id) throws CustomerException {
        if(mapper.findById(id) == null){
            throw new CustomerException(MessageStatus.SPECIFIED_QUESTIONED_COMMENT_NOT_EXIST);
        }
        mapper.deleteById(id);

    }



}
